package com.ylbh.modules.sign.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.reply.dto.CommunalDTO;
import com.ylbh.common.pojo.sign.dto.SignTurntableDTO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.sign.entity.ShoppingSigninPrize;
import com.ylbh.modules.sign.entity.ShoppingSigninTurntableInfo;
import com.ylbh.modules.sign.service.ShoppingSignTurntableService;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author; wjc
 * @date: 2019/12/17
 */
@RestController
@RequestMapping("sign")
public class ShoppingSignTurntableController {

    @Autowired
    private ShoppingSignTurntableService shoppingSignTurntableService;

    @ApiOperation("获取模板列表")
    @GetMapping("querySignTurntableList")
    public CommonResult<PageUtils> querySignTurntableList(SignTurntableDTO signTurntableDTO) {
        PageUtils turntableList = shoppingSignTurntableService.querySignTurntableList(signTurntableDTO);
        return Ref.ok(turntableList);
    }

    @RequestMapping("addTurntable")
    public CommonResult addTurntable(@RequestBody SignTurntableDTO signTurntableDTO) {
        shoppingSignTurntableService.addTurntable(signTurntableDTO);
        return Ref.ok();
    }

    @SysLog("获取模信息ById")
    @RequestMapping("getTurntableById/{id}")
    public CommonResult<ShoppingSigninTurntableInfo> getTurntableById(@PathVariable(value = "id") Integer id) {
        ShoppingSigninTurntableInfo classInfo = shoppingSignTurntableService.getTurntableById(id);
        return Ref.ok(classInfo);
    }

    @SysLog("根据ID修改模板信息")
    @ApiOperation("根据ID修改模板信息")
    @RequestMapping("modifyTurntableById")
    public CommonResult modifyTurntableById(@RequestBody SignTurntableDTO signTurntableDTO) {
        shoppingSignTurntableService.modifyTurntableById(signTurntableDTO);
        return  Ref.ok();
    }

    @SysLog("删除模板信息")
    @ApiOperation("删除模板信息")
    @RequestMapping("removeTurntableByIds")
    public CommonResult<Void> removeTurntableByIds(@RequestBody Integer[] Ids){
        shoppingSignTurntableService.removeTurntableByIds(Ids);
        return Ref.ok();
    }

    @SysLog("修改模板状态")
    @ApiOperation("修改模板状态")
    @RequestMapping("modifyTurnTableEnableStateById")
    public Boolean modifyTurnTableEnableStateById(@RequestBody SignTurntableDTO signTurntableDTO){
        Boolean flag = shoppingSignTurntableService.modifyTurnTableEnableStateById(signTurntableDTO);
        return flag;
    }

    @RequestMapping("uploadTurntable")
    public CommonResult<String> uploadTurntable(MultipartFile file, HttpServletRequest request) {
        String url = shoppingSignTurntableService.uploadTurntable(file, request);
        System.out.println(url);
        return Ref.ok(url);
    }
}
